import request from '@/utils/request'
import type { IResData } from './userAPI'

// interface 限制 添加表单对象的类型(请求体的类型)
export interface IAddNoticeform {
  name: string
}

export const noticeCateAddRequest = (body: IAddNoticeform) => {
  // axios《T》()
  // 请求实例《T》--》指定的 r.data的类型
  return request<IResData<number>>({
    url: '/admin/notice-category/create',
    method: 'post',
    data: body,
  })
}

export interface INoticeListItemRes {
  categoryId: string
  createTime: string
  flag: boolean
  name: string
  updateTime: string
  _id: string
}
export interface INoticeListRes {
  list: INoticeListItemRes[]
  pageNum: number
  pageSize: number
  total: number
}

export const noticeCateListRequest = (pageNum = 1, pageSize = 10) => {
  // axios《T》()
  // 请求实例《T》--》指定的 r.data的类型
  return request<IResData<INoticeListRes>>({
    url: '/admin/notice-category/list',
    method: 'get',
    params: { pageNum, pageSize },
  })
}

export const noticeCateDelByIdRequest = (categoryId: string) => {
  // axios《T》()
  // 请求实例《T》--》指定的 r.data的类型
  return request<IResData<number>>({
    // url: '/admin/notice-category/delete/:id',
    url: '/admin/notice-category/delete/' + categoryId,
    method: 'delete',
  })
}
export const noticeCateUpdateByIdRequest = (categoryId: string, name: string) => {
  // axios《T》()
  // 请求实例《T》--》指定的 r.data的类型
  return request<IResData<number>>({
    // url: '/admin/notice-category/delete/:id',
    url: '/admin/notice-category/update/' + categoryId,
    method: 'put',
    data: { name },
  })
}

/*
  通知公共相关接口
*/
export interface INoticeItem {
  title: string
  content: string
  // categoryId: string
  _id?: string
  createTime?: string
  updateTime?: string
  categoryId?: INoticeListItemRes | string
  id?: string
}
export interface INoticeData {
  list: INoticeItem[]
  pageNum: number
  pageSize: number
  total: number
}

export const noticeAddRequest = (body: INoticeItem) => {
  // axios《T》()
  // 请求实例《T》--》指定的 r.data的类型
  return request<IResData<INoticeData>>({
    url: '/admin/notice/create',
    method: 'post',
    data: body,
  })
}

export const noticeListRequest = () => {
  // axios《T》()
  // 请求实例《T》--》指定的 r.data的类型
  return request<IResData<INoticeData>>({
    url: '/admin/notice/list',
    method: 'get',
  })
}

export const noticeDelByIdRequest = (id: string) => {
  // axios《T》()
  // 请求实例《T》--》指定的 r.data的类型
  return request<IResData<number>>({
    url: '/admin/notice/delete/' + id,
    method: 'delete',
  })
}

export const noticeUpdateByIdRequest = (id: string, body: INoticeItem) => {
  // axios《T》()
  // 请求实例《T》--》指定的 r.data的类型
  return request<IResData<number>>({
    url: '/admin/notice/update/' + id,
    method: 'put',
    data: body,
  })
}
